package com.leetcode;

public class Date0404 {
    /**
     * https://leetcode.cn/problems/minimum-size-subarray-sum/
     * 长度最小的数组
     */

    public static void main(String[] args) {
        int target = 7;
        int[] nums = {2,3,1,2,4,3};
        System.out.println(minSubArrayLen(target, nums));
    }
    public static int minSubArrayLen(int target, int[] nums) {
       int sum = 0, len = Integer.MAX_VALUE;
       for(int left = 0, right = 0; right < nums.length; right++) {
           sum += nums[right];
           while (sum >= target) {len = Math.min(len, right - left + 1);
               sum -= nums[left++];

           }
       }
       return len == Integer.MAX_VALUE ? 0 : len;
    }
}
